home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / v8n20.arc / POPMENU.C < prev    next >
Text File  |  1989-10-26  |  4KB  |  114 lines

  1. /*---------------------------------------------------------
  2.    POPMENU.C -- Popup Menus for OS/2 Presentation Manager
  3.                 (c) 1989, Ziff Communications Co.
  4.                 PC Magazine * Charles Petzold, August 1989
  5.   ---------------------------------------------------------*/
  6.  
  7. #define INCL_WIN
  8. #include <os2.h>
  9. #include "popmenu.h"
  10.  
  11. MRESULT EXPENTRY ClientWndProc (HWND, USHORT, MPARAM, MPARAM) ;
  12. MRESULT EXPENTRY AboutDlgProc  (HWND, USHORT, MPARAM, MPARAM) ;
  13.  
  14. int main (void)
  15.      {
  16.      static CHAR  szClientClass[] = "PopMenu" ;
  17.      static ULONG flFrameFlags = FCF_TITLEBAR      | FCF_SYSMENU  |
  18.                                  FCF_SIZEBORDER    | FCF_MINMAX   |
  19.                                  FCF_SHELLPOSITION | FCF_TASKLIST |
  20.                                  FCF_MENU ;
  21.      HAB          hab ;
  22.      HMQ          hmq ;
  23.      HWND         hwndFrame, hwndClient ;
  24.      QMSG         qmsg ;
  25.  
  26.      hab = WinInitialize (0) ;
  27.      hmq = WinCreateMsgQueue (hab, DEFAULT_QUEUE_SIZE) ;
  28.  
  29.      WinRegisterClass (hab, szClientClass, ClientWndProc, 0L, 0) ;
  30.  
  31.      hwndFrame = WinCreateStdWindow (HWND_DESKTOP, WS_VISIBLE,
  32.                                      &flFrameFlags, szClientClass, NULL,
  33.                                      0L, NULL, ID_NORMAL, &hwndClient) ;
  34.  
  35.      while (WinGetMsg (hab, &qmsg, NULL, 0, 0))
  36.           WinDispatchMsg (hab, &qmsg) ;
  37.  
  38.      WinDestroyWindow (hwndFrame) ;
  39.      WinDestroyMsgQueue (hmq) ;
  40.      WinTerminate (hab) ;
  41.      return 0 ;
  42.      }
  43.  
  44. MRESULT EXPENTRY ClientWndProc (HWND hwnd, USHORT msg, 
  45.                                 MPARAM mp1, MPARAM mp2)
  46.      {
  47.      static HWND hwndMenuPopup ;
  48.      HPS         hps ;
  49.      POINTL      ptlMouse ;
  50.  
  51.      switch (msg)
  52.           {
  53.           case WM_CREATE:
  54.                hwndMenuPopup = WinLoadMenu (hwnd, NULL, ID_POPUP) ;
  55.                WinSetWindowPos (hwndMenuPopup, NULL, 
  56.                                 0, 0, 0, 0, SWP_SIZE) ;
  57.                WinSetParent (hwndMenuPopup, HWND_DESKTOP, FALSE) ;
  58.                return 0 ;
  59.  
  60.           case WM_BUTTON2UP:
  61.                WinQueryPointerPos (HWND_DESKTOP, &ptlMouse) ;
  62.                ptlMouse.y += WinQuerySysValue (HWND_DESKTOP, 
  63.                                                SV_CYMENU) ;
  64.  
  65.                WinSetWindowPos (hwndMenuPopup, NULL,
  66.                                 (SHORT) ptlMouse.x, (SHORT) ptlMouse.y,
  67.                                 0, 0, SWP_MOVE) ;
  68.  
  69.                WinSendMsg (hwndMenuPopup, MM_SELECTITEM,
  70.                            MPFROM2SHORT (IDM_POPUP, FALSE),
  71.                            MPFROMSHORT (FALSE)) ;
  72.  
  73.                WinSetCapture (HWND_DESKTOP, hwndMenuPopup) ;
  74.                return 0 ;
  75.  
  76.           case WM_COMMAND:
  77.                switch (COMMANDMSG(&msg)->cmd)
  78.                     {
  79.                     case IDM_ABOUT:
  80.                          WinDlgBox (HWND_DESKTOP, hwnd, AboutDlgProc,
  81.                                     NULL, IDD_ABOUT, NULL) ;
  82.                          return 0 ;
  83.                     }
  84.                break ;
  85.  
  86.           case WM_PAINT:
  87.                hps = WinBeginPaint (hwnd, NULL, NULL) ;
  88.                GpiErase (hps) ;
  89.                WinEndPaint (hps) ;
  90.                return 0 ;
  91.           }
  92.      return WinDefWindowProc (hwnd, msg, mp1, mp2) ;
  93.      }
  94.  
  95. MRESULT EXPENTRY AboutDlgProc (HWND hwnd, USHORT msg, 
  96.                                MPARAM mp1, MPARAM mp2)
  97.      {
  98.      switch (msg)
  99.           {
  100.           case WM_COMMAND:
  101.                switch (COMMANDMSG(&msg)->cmd)
  102.                     {
  103.                     case DID_OK:
  104.                     case DID_CANCEL:
  105.                          WinDismissDlg (hwnd, TRUE) ;
  106.                          return 0 ;
  107.                     }
  108.                break ;
  109.           }
  110.      return WinDefDlgProc (hwnd, msg, mp1, mp2) ;
  111.      }
  112.  
  113.  
  114.